#pragma once

#include "mysql_connection.h"
#include "mysql_handle.h"

#include <condition_variable>
#include <memory>
#include <mutex>
#include <queue>

class MySQLPool
{
public:
    MySQLPool(const std::string &host,
              uint16_t           port,
              const std::string &username,
              const std::string &password,
              const std::string &database,
              uint32_t           poolSize);
    ~MySQLPool();

public:
    /**
     * @brief 从连接池获取一个连接
     *
     * @return std::shared_ptr<MySQLConnection>
     */
    std::shared_ptr<MySQLConnection> acquire();

    /**
     * @brief 释放一个连接到连接池
     *
     * @param handle
     */
    void release(MySQLHandle *handle);

private:
    std::queue<MySQLHandle *> pool_;
    std::mutex                mutex_;
    std::condition_variable   cond_;
};